//
//  XYRightItmesHeaderView.swift
//  XYReadBook
//
//  Created by fox on 2017/12/23.
//  Copyright © 2017年 tsaievan. All rights reserved.
//

import UIKit

class XYRightItmesHeaderView: UIView {
    var bookIconImg = UIImageView()
    var boookName = UILabel()
    var bookDetails = UILabel()
    var lineView = UIView()
    var bookIcon:UIImage
    var bookNameStr:String
    var gotoBookDetailsBlock:(() ->Void)?
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//        setupUI()
//    }
    init(bookIcon:UIImage,frame:CGRect,bookNameStr:String) {
        self.bookIcon = bookIcon
        self.bookNameStr = bookNameStr
        super.init(frame: frame)
        setupUI()
    }

    func setupUI() {
        bookIconImg.image = bookIcon
        addSubview(bookIconImg)
        bookIconImg.backgroundColor = UIColor.init(red: 100 / 255.0, green: 100/255.0, blue: 100/255.0,alpha: 1)
        addSubview(boookName)
        addSubview(bookDetails)
        addSubview(lineView)
        bookDetails.font = UIFont.systemFont(ofSize: 12)
        bookDetails.text = "查看书本详情"
        bookDetails.textColor = UIColor.hm_color(withRed: 200, green: 200, blue: 200)
        lineView.backgroundColor = UIColor.white
        boookName.font = UIFont.systemFont(ofSize: 14)
        boookName.text = bookNameStr
        boookName.textColor = UIColor.white

        // 添加手势跳转书籍详情
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(gotoBookDetails))
        addGestureRecognizer(tap)
    }


    /// 跳转书籍详情
    func gotoBookDetails() {
        gotoBookDetailsBlock?()
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        bookIconImg.frame = CGRect(x: 12, y: 6, width: self.width * 0.3, height: self.height - 12)
        boookName.frame = CGRect(x: bookIconImg.frame.maxX + 6, y: bookIconImg.y + 6, width: self.width * 0.5, height: 20)
        bookDetails.frame = CGRect(x: boookName.x, y: bookIconImg.height - 22, width: self.width * 0.7, height: 20)
        lineView.frame = CGRect(x: 12, y: self.height - 2, width: self.width - 6, height: 1)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
